package com.dp.singleton;

/**
 * @Author: Ruomeng
 * @Date: 2024/11/5
 * @Description : 单例模式-懒汉式(非线程安全)
 * 支持延时加载，仅调用getInstance方法时，才会创建对象
 */
public class LazySingletonUnsafe {

    //1.私有构造方法
    private LazySingletonUnsafe() {
    }

    //2.在本类中创建私有静态对象
    private static LazySingletonUnsafe lazyInstance;

    //3.通过判断对象是否被初始化，来选择是否创建对象
    public static LazySingletonUnsafe getInstance() {
        if (lazyInstance == null) {
            lazyInstance = new LazySingletonUnsafe();
        }
        return lazyInstance;
    }

}
